<?php
if (!defined( "IN_UCHOME" ) ) exit( "Access Denied" );
require_once('class.action.php');
class show extends action
{

	function get_data($id, $format = true)
	{
		global $uid;
		$data = $this->query_one("select * from  ".tname("app_action") . " where id = '{$id}' ");
		if(empty($data)) return false;
		realname_set($data['uid'], $data['username']);
		if($format == false) return $data;
		$data['form'] = $this->show_form($data['id'], $data, $this->get_event_status($data['id'], $uid));
		$data['start_time'] = sgmdate('Y-n-d H:i', $data['start_time']);
		$data['end_time'] = sgmdate('Y-n-d H:i', $data['end_time']);
		$data['dateline'] = sgmdate('Y-n-d H:i', $data['dateline'], 1);
		return $data;
	}

	function get_reply($id)
	{
		$data = $this->query_all("select * from ".tname("app_action_reply") . " where id = '{$id}' ");
		$pid = $parent = array();
		foreach($data as $key=>$val){
			$pid[$key] = $val['pid'];
			$parent[$key] = $val['parentid'];
			$data[$key]['style'] = $val['dpath'] * 53;
			$data[$key]['dateline'] = sgmdate('Y-n-d H:i', $val['dateline'], true);
			$data[$key]['message'] = nl2br($val['message']);
		}
		array_multisort($parent, SORT_ASC, $pid, SORT_ASC, $data);
		return $data;
	}
	
	function get_user($id)
	{
		$temp = $this->query_all("select * from ".tname("app_action_join") . " where id = '{$id}' ");
		$data = array('join'=> array(), 'interest'=>array());
		foreach($temp as $key=>$val){
			if($val['is_pass'] == 0) continue;
			realname_set($val['uid'], $val['username']);
			$data[$val['type']][] = $val;
		}
		return $data;
	}

	function get_album($id, $limit = 5)
	{
		$temp = $this->query_all("select * from ".tname("app_action_album") . " where id = '{$id}' order by pid desc {$ext}");
		return $limit > 0 ? array_slice($temp, 0, $limit) : $temp;
	}

	function get_picture($pid)
	{
		return $this->query_one("select * from ".tname("app_action_album") . " where pid = '{$pid}' ");
	}

	function del_picture($pid)
	{
		return $this->query_exec("delete  from ".tname("app_action_album") . " where pid = '{$pid}' ");
	}

	function delete($id)
	{
		$this->query_exec("delete  from ".tname("app_action_album") . " where id = '{$id}' ");
		$this->query_exec("delete  from ".tname("app_action_join") . " where id = '{$id}' ");
		$this->query_exec("delete  from ".tname("app_action_reply") . " where id = '{$id}' ");
		$this->query_exec("delete  from ".tname("app_action") . " where id = '{$id}' ");
	}

	function check_hash($id, $hash)
	{
		global $uid;
		$temp = $this->query_one("select count(*) as num from ".tname("app_action_invite")." where id = '{$id}' and uid = {$uid} and hash = '{$hash}' ");
		return $temp['num'];
	}

	function check_user($id)
	{
		global $uid;
		$temp = $this->query_one("select count(*) as num from ".tname("app_action_join") . " where id = '{$id}' and uid = '{$uid}' and type = 'join' and is_pass = 1");
		return $temp['num'];
	}

	function check_friend($fuid)
	{
		global $uid;
		$temp = $this->query_one("select count(*) as num from ".tname("friend") . " where uid = '{$uid}' and fuid = '{$fuid}' and status = 1");
		return $temp['num'];
	}
}
?>